package com.example.login.Mapper;

import com.example.login.Pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
@Mapper
public interface GoodsMap {
    @Insert("insert into xtshop_goods(seller_id,item_name,store_name,brand_name,goodImage,cid,fright,goodStatus,sell_num,min_price) " +
            "values(#{seller_id},#{title},#{store_name},#{brand_name},#{image},#{cid},#{fright},1,0,#{min_price})")
    void AddGoods(int seller_id,String title,String store_name,String brand_name,String image,String cid,int fright,int min_price);
    @Select("select * from xtshop_goods where seller_id=#{seller_id} and item_name=#{title}")
    Goods getGoodsBySellerIdAndTitle(int seller_id,String title);
    @Select("select * from xtshop_goods natural join xtshop_mp3 ")
    List<mp3Goods> getMp3Goods();
    @Select("select * from xtshop_goods natural join xtshop_pc ")
    ArrayList<PCGoods> getPCGoods();
    @Select("select * from xtshop_goods natural join xtshop_mobilephone ")
    List<mobileGoods> getMobileGoods();
    @Update("UPDATE xtshop_pc SET `status`=#{status} WHERE id=#{id} AND sku_code=#{sku_code}")
    void PcOffShelf(int id,String sku_code,int status);
    @Update("UPDATE xtshop_mp3 SET `status`=#{status} WHERE id=#{id} AND sku_code=#{sku_code}")
    void Mp3OffShelf(int id,String sku_code,int status);
    @Update("UPDATE xtshop_mobilephone SET `status`=#{status} WHERE id=#{id} AND sku_code=#{sku_code}")
    void MobileOffShelf(int id,String sku_code,int status);
    //获取cid
    @Select("select cid from xtshop_goods where id=#{id}")
    String determine(int id);
    @Select("select * from xtshop_pc where id=#{id} and sku_code=#{sku_code}")
    PC DeterminePcStatus(int id, String sku_code);
    @Select("select * from xtshop_mp3 where id=#{id} and sku_code=#{sku_code}")
    MP3 DetermineMp3Status(int id,  String sku_code);
    @Select("select * from xtshop_mobilephone where id=#{id} and sku_code=#{sku_code}")
    MobilePhone DetermineMoibleStatus(int id, String sku_code);
    @Update("update xtshop_goods SET fright=#{fright} where id=#{id}")
    void ModifyPrice(int id,int fright);
    @Delete("delete from xtshop_goods where id=#{id}")
    void delete(int id);
    @Select("select * from xtshop_goods where seller_id=#{seller_id} and item_name=#{title}")
    int getIdBySellerIdAndName(int seller_id,String title);

    //获取MP3GOODS
    @Select("select * from xtshop_goods natural join xtshop_mp3 where id=#{id} and sku_code=#{sku_code}")
    mp3Goods getMp3Good(int id,String sku_code);
    @Select("select * from xtshop_goods natural join xtshop_pc where id=#{id} and sku_code=#{sku_code}")
    PCGoods getPCGood(int id,String sku_code);
    @Select("select * from xtshop_goods natural join xtshop_mobilephone where id=#{id} and sku_code=#{sku_code}")
    mobileGoods getMobileGood(int id,String sku_code);

    //更新goods的图片路径
    @Update("UPDATE xtshop_goods SET goodImage=#{path} where id =#{id}")
    void updateGoodImage(String path,int id);

    @Update("update  xtshop_goods set min_price=#{min_price} where seller_id=#{seller_id} and item_name=#{title}")
    void updateMin(int seller_id,String title,int min_price);
    @Select("select min_price from xtshop_goods where seller_id=#{seller_id} and item_name=#{title}")
    int getMinPrice(int seller_id,String title);

    @Select("select * from xtshop_goods where goodStatus = 1")
    ArrayList<Goods>    getGoods();
    @Select("select * from xtshop_goods where goodStatus = 1 order by sell_num")
    ArrayList<Goods>    getGoodsOrderBySale();
    @Select("select * from xtshop_goods where cid='MobilePhone'")
    ArrayList<Goods> getMobile();
    @Select("select * from xtshop_goods where cid='MP3'")
    ArrayList<Goods> getMp3();
    @Select("select * from xtshop_goods where cid='PC'")
    ArrayList<Goods> getPc();

    @Select("select * from xtshop_goods natural join xtshop_mp3 where id =#{id}")
    List<mp3Goods> getMp3GoodsById(int id );
    @Select("select * from xtshop_goods natural join xtshop_pc where id =#{id}")
    List<PCGoods> getPCGoodsById(int id);
    @Select("select * from xtshop_goods natural join xtshop_mobilephone where id =#{id}")
    List<mobileGoods> getMobileGoodsById(int id);

    @Select("select * from xtshop_goods natural join xtshop_mp3 where id =#{id}and sku_code=#{sku_code}")
    List<mp3Goods> getMp3GoodsByIdAndSku(int id,String sku_code);
    @Select("select * from xtshop_goods natural join xtshop_pc where id =#{id} and sku_code=#{sku_code}")
    List<PCGoods> getPCGoodsByIdAndSku(int id,String sku_code);
    @Select("select * from xtshop_goods natural join xtshop_mobilephone where id =#{id} and sku_code=#{sku_code}")
    List<mobileGoods> getMobileGoodsByIdAndSku(int id,String sku_code);
    @Select("select store_name from xtshop_goods where id =#{id}")
    String getStoreNameByID(int id);

    //根据id获取商品
    @Select("select * from xtshop_goods where id =#{id}")
    Goods getGoodsById(int id);
    //根据卖家id获取商品列表
    @Select("select * from xtshop_goods where seller_id =#{seller_id}")
    ArrayList<Goods> getGoodsList(int seller_id);

    //销量
    @Update("update xtshop_goods set sell_num=sell_num+#{num} where id=#{id};")
    void updateSellNum(int num,int id);

    //根据商家id取东西
    @Select("Select * from xtshop_goods where seller_id=#{seller_id}")
    ArrayList<Goods> getGoodsBySellerId(int seller_id);
}
